<?php
   class Model_activity extends CI_Model{
		protected $_table = "tbl_activity";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function getcolunm_allactivity($column){
			$this->db->select($column);
			return $this->db->get($this->_table)->result_array();
		}
		public function listall($limit,$start){
			$this->db->limit($limit,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listtopbyprovide_orderby($limit,$start,$provide,$orderby){						
			$query=$this->db->query("select * from tbl_activity where provide like '%".$provide."%' order by ".$orderby." limit ".$start.",".$limit);	
			return $query->result_array();
		}
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		public function countrow(){
			$countrow=$this->db->query("select count(*) as total from tbl_activity");	
			return $countrow->row_array();	
		}
		public function countallbyprovide($provide){
			$query=$this->db->query("select count(*) as total from tbl_activity where provide like '%".$provide."%'");
			return $query->row_array();
		}
		public function count_search(){
			$query=$this->db->query("select count(*) as total from tbl_activity");	
			return $query->row_array();
		}
		public function get_search($provide,$type,$price,$sortby,$name,$datefrom,$limit,$start){			
			$query="select *,(select pricefor16 from tbl_activityprice where activityid=h.id and datefrom <= '".$datefrom."' and dateto >= '".$datefrom."' order by pricefor16 limit 0,1) as price from tbl_activity as h ";
			$limit=" limit ".$start.",".$limit;
			$order='';			
			if(isset($sortby) && $sortby!='') $order=" order by ".$sortby;
			$where= ' where 1=1 ';
			if(isset($provide) && $provide!='') $where.= " and provide like '%".$provide."%'";
			if(isset($type) && $type!='') $where.= $type;
			if(isset($name) && $name!='') $where.=" and name like '%".$name."%'";
			$query2=$this->db->query($query.$where.$order.$limit);
			return $query2->result_array();
		}
		public function gettopByprovide_status($provide,$status,$limit,$start){
			$query=$this->db->query("select * from tbl_activity where provide like '%".$provide."%' and status=".$status." order by recommendations limit ".$start.",".$limit);	
			return $query->result_array();
		}
		
		//admin
		public function getallbyprovide_name($provide,$name){
			$select="select * from tbl_activity ";	
			$order=" order by name ";
			$where=" where 1=1 ";
			if($provide!='0') $where.=" and provide like '%".$provide."%'";
			if($name!='') $where.=" and name like '%".$name."%'";
			$query=$this->db->query($select.$where.$order);
			return $query->result_array();
		}
		
		public function countbytype($type){
			$query=$this->db->query("select count(*) as total from tbl_activity where typeofactivity like '%".$type."%'");
			return $query->row_array();
		}
	}
?>